###############################################################################
# Senators at Home 
# By Jaclyn Kaslovsky  
###############################################################################

# Packages ##############################################

require(readstata13)
require(lfe)
require(dplyr)
require(stargazer)
require(starpolishr)
require(dplyr)

#####################################
######## Total Trips Home ###########
#####################################

#load the data
data_total <- read.dta13("TotalResources_Home.dta",convert.factors=FALSE)

reg1 <- felm(log_indist ~ votepct + seniority + log_miles + logpop + log_dist | cong | 0 | icpsr, data = data_total)

reg2 <- felm(log_indist ~ votepct + seniority + log_miles + logpop + log_dist + female + absnokken + rep + up_for_election  + 
               majority + chair + power | cong | 0 | icpsr, data = data_total)

table1 <- stargazer(reg1, reg2,
                    add.lines=list(c("Congress Fixed Effects","\\checkmark","\\checkmark")),
                    notes.append = FALSE, notes.label = "",
                    report="vc*s",star.char=c("*","**"),star.cutoffs = c(0.10,0.05),no.space = TRUE,
                    omit.stat = c("rsq", "ser","f"), font.size = "footnotesize",
                    dep.var.caption  = "ln(Number of Trips to State)",
                    dep.var.labels = "", model.numbers = FALSE,
                    column.labels=c("(1)","(2)"), align=TRUE,
                    covariate.labels=c("Previous General Election Vote Share", "Seniority", "Logged State Square Miles",
                                       "Logged State Population", "Logged Distance from Washington D.C.", "Woman Legislator",
                                       "$|$Nokken-Poole Score$|$", "Republican", "Senator's Election Year", "Majority", "Chair",
                                       "Power Committee"),
                    notes="\\parbox[t]{.78\\textwidth}{\\footnotesize \\textit{Note}: Entries are linear regression coefficients with standard errors (clustered on senator) shown in parentheses. The dependent variable is logged number of trips a senator makes home in a given Congress. $^*$ indicates $p<0.10$ and $^{**} p<0.05$ (two tailed tests).}",
                    label="whogo",
                    digits=3,
                    digits.extra = 0,
                    title="The Relationship between Legislator Characteristics and Trips Home")
cat(table1, sep = '\n', file = "TableB1.tex")

########################################
######## Total Staffer Ratio ###########
########################################

reg3 <- felm(staff_per ~ votepct + seniority + log_miles + logpop + log_dist | cong | 0 | icpsr, data = data_total)

reg4 <- felm(staff_per ~ votepct + seniority + log_miles + logpop + log_dist + female + absnokken + rep + up_for_election  + 
               majority + chair + power | cong | 0 | icpsr, data = data_total)

table2 <- stargazer(reg3, reg4,
                    add.lines=list(c("Congress Fixed Effects","\\checkmark","\\checkmark")),
                    notes.append = FALSE, notes.label = "",
                    report="vc*s",star.char=c("*","**"),star.cutoffs = c(0.10,0.05),no.space = TRUE,
                    omit.stat = c("rsq", "ser","f"), font.size = "footnotesize",
                    dep.var.caption  = "Percentage of Staffers in State Offices",
                    dep.var.labels = "", model.numbers = FALSE,
                    column.labels=c("(1)","(2)"), align=TRUE,
                    covariate.labels=c("Previous General Election Vote Share", "Seniority", "Logged State Square Miles",
                                       "Logged State Population", "Logged Distance from Washington D.C.", "Woman Legislator",
                                       "$|$Nokken-Poole Score$|$", "Republican", "Senator's Election Year", "Majority", "Chair",
                                       "Power Committee"),
                    notes="\\parbox[t]{.78\\textwidth}{\\footnotesize \\textit{Note}: Entries are linear regression coefficients with standard errors (clustered on senator) shown in parentheses. The dependent variable is the percent of staff placed in state offices in a given Congress. $^*$ indicates $p<0.10$ and $^{**} p<0.05$ (two tailed tests).}",
                    label="whostaff",
                    digits=3,
                    digits.extra = 0,
                    title="The Relationship between Legislator Characteristics and Staff Allocation")
cat(table2, sep = '\n', file = "TableB2.tex")


#############################################################
#############################################################
# Predicting where senators go and staff Appendix Results
#############################################################
#############################################################

#load the data
data_county <- read.dta13("resources_tocounties_final.dta",convert.factors=FALSE)

data_msa <- read.dta13("resources_tomsa_final.dta",convert.factors=FALSE)

############################################
# Alternative core and swing specifications
############################################

#visits
reg5_county_alt <- felm(traveledonce ~ core2 + party_sd + greaterdon + logpop + median_hhincome + per_white + has_flight + seniority + chair + power + majority + electionyear + has_capital | year + icpsr | 0 | icpsr, data = data_county)

reg6_county_alt <- felm(log_traveled ~ core2 + party_sd + greaterdon + logpop + median_hhincome + per_white + has_flight + seniority + chair + power + majority + electionyear + has_capital | year + icpsr | 0 | icpsr, data = data_county)

reg7_county_alt <- felm(traveled ~ core2 + party_sd + greaterdon + logpop + median_hhincome + per_white + has_flight + seniority + chair + power + majority + electionyear + has_capital | year + icpsr | 0 | icpsr, data = data_county)

reg5_msa_alt <- felm(traveledonce ~ core2 + party_sd + greaterdon + logpop + median_hhincome + per_white + has_flight + seniority + chair + power + majority + electionyear + has_capital | year + icpsr | 0 | icpsr, data = data_msa)

reg6_msa_alt <- felm(log_traveled ~ core2 + party_sd + greaterdon + logpop + median_hhincome + per_white + has_flight + seniority + chair + power + majority + electionyear + has_capital | year + icpsr | 0 | icpsr, data = data_msa)

reg7_msa_alt <- felm(traveled ~ core2 + party_sd + greaterdon + logpop + median_hhincome + per_white + has_flight + seniority + chair + power + majority + electionyear + has_capital | year + icpsr | 0 | icpsr, data = data_msa)

#staff
reg8_county_alt <- felm(staffeddonce ~ core2 + party_sd + greaterdon + logpop + median_hhincome + per_white + has_flight + seniority + chair + power + majority + electionyear + has_capital | year + icpsr | 0 | icpsr, data = data_county)

reg9_county_alt <- felm(log_staffed ~ core2 + party_sd + greaterdon + logpop + median_hhincome + per_white + has_flight + seniority + chair + power + majority + electionyear + has_capital | year + icpsr | 0 | icpsr, data = data_county)

reg10_county_alt <- felm(staff_per ~ core2 + party_sd + greaterdon + logpop + median_hhincome + per_white + has_flight + seniority + chair + power + majority + electionyear + has_capital | year + icpsr | 0 | icpsr, data = data_county)

reg8_msa_alt <- felm(staffeddonce_msa ~ core2 + party_sd + greaterdon + logpop + median_hhincome + per_white + has_flight + seniority + chair + power + majority + electionyear + has_capital | year + icpsr | 0 | icpsr, data = data_msa)

reg9_msa_alt <- felm(log_staffed_msa ~ core2 + party_sd + greaterdon + logpop + median_hhincome + per_white + has_flight + seniority + chair + power + majority + electionyear + has_capital | year + icpsr | 0 | icpsr, data = data_msa)

reg10_msa_alt <- felm(staff_per_msa ~ core2 + party_sd + greaterdon + logpop + median_hhincome + per_white + has_flight + seniority + chair + power + majority + electionyear + has_capital | year + icpsr | 0 | icpsr, data = data_msa)



county_alt <- stargazer(reg5_county_alt, reg7_county_alt, reg6_county_alt,reg8_county_alt, reg10_county_alt,reg9_county_alt,
                        omit=c("seniority", "chair", "power", "majority", "has_flight", "electionyear", "has_capital"),
                        add.lines=list(c("Senator-County Fixed Effects","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark"),
                                       c("Year Fixed Effects","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark")),
                        notes.append = FALSE, notes.label = "",
                        report="vc*s",star.char=c("*","**"),star.cutoffs = c(0.10,0.05),no.space = TRUE,
                        omit.stat = c("rsq", "ser","f"), font.size = "footnotesize",
                        dep.var.caption  = "",
                        dep.var.labels = c("", "", "","", "", ""), model.numbers = FALSE,
                        column.labels=c("Any Visits","Total Visits", "ln(Visits + 1)","Any Staff", "Pct. Staff","ln(Pct. of Staff + 1)"), align=TRUE,
                        covariate.labels=c("Greater than 55 Past 3 Elections", "SD of Party Vote Past 3 Elections", "Above Avg. Donations to Party", "Log Population", "Median Household Income", "Percent White"),
                        notes="\\parbox[t]{1.05\\textwidth}{\\footnotesize \\textit{Note}: Entries are linear regression coefficients with standard errors (clustered on senator) shown in parentheses. The dependent variables are various transformations of the number of resources a senator allocates to an area. $^*$ indicates $p<0.10$ and $^{**} p<0.05$ (two tailed tests).}",
                        label="standard",
                        digits=3,
                        digits.extra = 0,column.sep.width = "-8pt",
                        title="The Relationship between Local Characteristics and Senator Resource Allocation using Alternative Measures of Core and Swing")

msa_alt <- stargazer(reg5_msa_alt, reg7_msa_alt,reg6_msa_alt, reg8_msa_alt, reg10_msa_alt, reg9_msa_alt,
                     omit=c("seniority", "chair", "power", "majority", "has_flight", "electionyear", "has_capital"),
                     add.lines=list(c("Senator-MSA Fixed Effects","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark"),
                                    c("Year Fixed Effects","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark")),
                     notes.append = FALSE, notes.label = "",
                     report="vc*s",star.char=c("*","**"),star.cutoffs = c(0.10,0.05),no.space = TRUE,
                     omit.stat = c("rsq", "ser","f"), font.size = "footnotesize",
                     dep.var.caption  = "",
                     dep.var.labels = c("", "", "","", "", ""), model.numbers = FALSE,
                     column.labels=c("Any Visits", "Total Visits","ln(Visits + 1)","Any Staff", "Pct. Staff","ln(Pct. of Staff + 1)"), align=TRUE,
                     covariate.labels=c("Greater than 55 Past 3 Elections", "SD of Party Vote Past 3 Elections", "Above Avg. Donations to Party", "Log Population", "Avg. Median Household Income", "Percent White"),
                     notes="",
                     label="standard",
                     digits=3,
                     digits.extra = 0,column.sep.width = "-8pt",
                     title="")

star.panel.out <- star_panel(county_alt, msa_alt,panel.label.fontface="bold",
                             panel.names = c("County", "Metropolitan Statistical Area"), same.summary.stats = FALSE)
cat(star.panel.out, sep = '\n', file = "TableC1.tex")

##########################################
# Transportation receipts
##########################################

reg5_county_transportation <- felm(traveledonce_transportation ~ core + swing + greaterdon + logpop + median_hhincome + per_white + has_flight + seniority + chair + power + majority + electionyear + has_capital | year + icpsr | 0 | icpsr, data = data_county)

reg6_county_transportation <- felm(log_traveled_transportation ~ core + swing + greaterdon + logpop + median_hhincome + per_white + has_flight + seniority + chair + power + majority + electionyear + has_capital | year + icpsr | 0 | icpsr, data = data_county)

reg7_county_transportation <- felm(traveled_transportation ~ core + swing + greaterdon + logpop + median_hhincome + per_white + has_flight + seniority + chair + power + majority + electionyear + has_capital | year + icpsr | 0 | icpsr, data = data_county)

reg5_msa_transportation <- felm(traveledonce_transportation ~ core + swing + greaterdon + logpop + median_hhincome + per_white + has_flight + seniority + chair + power + majority + electionyear + has_capital | year + icpsr | 0 | icpsr, data = data_msa)

reg6_msa_transportation <- felm(log_traveled_transportation ~ core + swing + greaterdon + logpop + median_hhincome + per_white + has_flight + seniority + chair + power + majority + electionyear + has_capital | year + icpsr | 0 | icpsr, data = data_msa)

reg7_msa_transportation <- felm(traveled_transportation ~ core + swing + greaterdon + logpop + median_hhincome + per_white + has_flight + seniority + chair + power + majority + electionyear + has_capital | year + icpsr | 0 | icpsr, data = data_msa)



visits_county_transportation <- stargazer(reg5_county_transportation,  reg7_county_transportation,reg6_county_transportation,
                                          omit=c("seniority", "chair", "power", "majority", "has_flight", "electionyear", "has_capital"),
                                          add.lines=list(c("Senator-County Fixed Effects","\\checkmark","\\checkmark","\\checkmark"),
                                                         c("Year Fixed Effects","\\checkmark","\\checkmark","\\checkmark")),
                                          notes.append = FALSE, notes.label = "",
                                          report="vc*s",star.char=c("*","**"),star.cutoffs = c(0.10,0.05),no.space = TRUE,
                                          omit.stat = c("rsq", "ser","f"), font.size = "footnotesize",
                                          dep.var.caption  = "",
                                          dep.var.labels = c("", "", ""), model.numbers = FALSE,
                                          column.labels=c("Any Visits", "Total Visits","ln(Visits + 1)"), align=TRUE,
                                          covariate.labels=c("Core Area", "Swing Area", "Above Avg. Donations to Party", "Log Population", "Median Household Income", "Percent White"),
                                          notes="\\parbox[t]{.75\\textwidth}{\\footnotesize \\textit{Note}: Entries are linear regression coefficients with standard errors (clustered on senator) shown in parentheses. The dependent variables are various transformations of the number of trips a senator makes to an area. $^*$ indicates $p<0.10$ and $^{**} p<0.05$ (two tailed tests).}",
                                          label="tripscountiesmembertransportation",
                                          digits=3,
                                          digits.extra = 0,column.sep.width = "-8pt",
                                          title="The Relationship between Local Characteristics and Senator Travel Behavior using Transportation Receipts")

visits_msa_transportation <- stargazer(reg5_msa_transportation, reg7_msa_transportation, reg6_msa_transportation,
                                       omit=c("seniority", "chair", "power", "majority", "has_flight", "electionyear", "has_capital"),
                                       add.lines=list(c("Senator-MSA Fixed Effects","\\checkmark","\\checkmark","\\checkmark"),
                                                      c("Year Fixed Effects","\\checkmark","\\checkmark","\\checkmark")),
                                       notes.append = FALSE, notes.label = "",
                                       report="vc*s",star.char=c("*","**"),star.cutoffs = c(0.10,0.05),no.space = TRUE,
                                       omit.stat = c("rsq", "ser","f"), font.size = "footnotesize",
                                       dep.var.caption  = "",
                                       dep.var.labels = c("", "", ""), model.numbers = FALSE,
                                       column.labels=c("Any Visits", "Total Visits","ln(Visits + 1)"), align=TRUE,
                                       covariate.labels=c("Core Area", "Swing Area", "Above Avg. Donations to Party", "Log Population", "Avg. Median Household Income", "Percent White"),
                                       notes="",
                                       label="tripscountiesmembertransportation",
                                       digits=3,
                                       digits.extra = 0,column.sep.width = "-8pt",
                                       title="")

star.panel.out <- star_panel(visits_county_transportation, visits_msa_transportation,panel.label.fontface="bold",
                             panel.names = c("County", "Metropolitan Statistical Area"), same.summary.stats = FALSE)
cat(star.panel.out, sep = '\n', file = "TableC3.tex")

##########################################
# Using alternative measure of donations
##########################################

reg5_county_donations <- felm(traveledonce ~ core + swing + donations_pop + logpop + median_hhincome + per_white + has_flight + seniority + chair + power + majority + electionyear + has_capital | year + icpsr | 0 | icpsr, data = data_county)

reg6_county_donations <- felm(log_traveled ~ core + swing + donations_pop + logpop + median_hhincome + per_white + has_flight + seniority + chair + power + majority + electionyear + has_capital | year + icpsr | 0 | icpsr, data = data_county)

reg7_county_donations <- felm(traveled ~ core + swing + donations_pop + logpop + median_hhincome + per_white + has_flight + seniority + chair + power + majority + electionyear + has_capital | year + icpsr | 0 | icpsr, data = data_county)

reg5_msa_donations <- felm(traveledonce ~ core + swing + donations_pop + logpop + median_hhincome + per_white + has_flight + seniority + chair + power + majority + electionyear + has_capital | year + icpsr | 0 | icpsr, data = data_msa)

reg6_msa_donations <- felm(log_traveled ~ core + swing + donations_pop + logpop + median_hhincome + per_white + has_flight + seniority + chair + power + majority + electionyear + has_capital | year + icpsr | 0 | icpsr, data = data_msa)

reg7_msa_donations <- felm(traveled ~ core + swing + donations_pop + logpop + median_hhincome + per_white + has_flight + seniority + chair + power + majority + electionyear + has_capital | year + icpsr | 0 | icpsr, data = data_msa)

reg8_county_donations <- felm(staffeddonce ~ core + swing + donations_pop + logpop + median_hhincome + per_white + has_flight + seniority + chair + power + majority + electionyear + has_capital | year + icpsr | 0 | icpsr, data = data_county)

reg9_county_donations <- felm(log_staffed ~ core + swing + donations_pop + logpop + median_hhincome + per_white + has_flight + seniority + chair + power + majority + electionyear + has_capital | year + icpsr | 0 | icpsr, data = data_county)

reg10_county_donations <- felm(staff_per ~ core + swing + donations_pop + logpop + median_hhincome + per_white + has_flight + seniority + chair + power + majority + electionyear + has_capital | year + icpsr | 0 | icpsr, data = data_county)

reg8_msa_donations <- felm(staffeddonce_msa ~ core + swing + donations_pop + logpop + median_hhincome + per_white + has_flight + seniority + chair + power + majority + electionyear + has_capital | year + icpsr | 0 | icpsr, data = data_msa)

reg9_msa_donations <- felm(log_staffed_msa ~ core + swing + donations_pop + logpop + median_hhincome + per_white + has_flight + seniority + chair + power + majority + electionyear + has_capital | year + icpsr | 0 | icpsr, data = data_msa)

reg10_msa_donations <- felm(staff_per_msa ~ core + swing + donations_pop + logpop + median_hhincome + per_white + has_flight + seniority + chair + power + majority + electionyear + has_capital | year + icpsr | 0 | icpsr, data = data_msa)



county_donations <- stargazer(reg5_county_donations, reg7_county_donations,reg6_county_donations, reg8_county_donations, reg10_county_donations,reg9_county_donations,
                              omit=c("seniority", "chair", "power", "majority", "has_flight", "electionyear", "has_capital"),
                              add.lines=list(c("Senator-County Fixed Effects","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark"),
                                             c("Year Fixed Effects","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark")),
                              notes.append = FALSE, notes.label = "",
                              report="vc*s",star.char=c("*","**"),star.cutoffs = c(0.10,0.05),no.space = TRUE,
                              omit.stat = c("rsq", "ser","f"), font.size = "footnotesize",
                              dep.var.caption  = "",
                              dep.var.labels = c("", "", "","", "", ""), model.numbers = FALSE,
                              column.labels=c("Any Visits","Total Visits","ln(Visits + 1)","Any Staff", "Pct. Staff","ln(Pct. of Staff + 1)"), align=TRUE,
                              covariate.labels=c("Core Area", "Swing Area", "Same Party Donations per Population", "Log Population", "Median Household Income", "Percent White"),
                              notes="\\parbox[t]{1.05\\textwidth}{\\footnotesize \\textit{Note}: Entries are linear regression coefficients with standard errors (clustered on senator) shown in parentheses. The dependent variables are various transformations of the number of resources a senator allocates to an area. $^*$ indicates $p<0.10$ and $^{**} p<0.05$ (two tailed tests).}",
                              label="tripscountiesmemberdonations",
                              digits=3,
                              digits.extra = 0,column.sep.width = "-8pt",
                              title="The Relationship between Local Characteristics and Senator Resource Allocation using an Alternative Measure of Donations")

msa_donations <- stargazer(reg5_msa_donations, reg7_msa_donations,reg6_msa_donations, reg8_msa_donations, reg10_msa_donations,reg9_msa_donations,
                           omit=c("seniority", "chair", "power", "majority", "has_flight", "electionyear", "has_capital"),
                           add.lines=list(c("Senator-MSA Fixed Effects","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark"),
                                          c("Year Fixed Effects","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark")),
                           notes.append = FALSE, notes.label = "",
                           report="vc*s",star.char=c("*","**"),star.cutoffs = c(0.10,0.05),no.space = TRUE,
                           omit.stat = c("rsq", "ser","f"), font.size = "footnotesize",
                           dep.var.caption  = "",
                           dep.var.labels = c("", "", "","", "", ""), model.numbers = FALSE,
                           column.labels=c("Any Visits","Total Visits","ln(Visits + 1)","Any Staff", "Pct. Staff","ln(Pct. of Staff + 1)"), align=TRUE,
                           covariate.labels=c("Core Area", "Swing Area", "Same Party Donations per Population", "Log Population", "Avg. Median Household Income", "Percent White"),
                           notes="",
                           label="tripscountiesmemberdonations",
                           digits=3,
                           digits.extra = 0,column.sep.width = "-8pt",
                           title="")

star.panel.out <- star_panel(county_donations, msa_donations,panel.label.fontface="bold",
                             panel.names = c("County", "Metropolitan Statistical Area"), same.summary.stats = FALSE)
cat(star.panel.out, sep = '\n', file = "TableC2.tex")



#############################
#### Model of selection #####
#############################

data_total <- data_total %>%
  select(stateabrev, log_miles)
data_total <- unique(data_total)
data_county<- left_join(data_county, data_total, by="stateabrev")
total <- data_county %>% 
  group_by(stateabrev, electionyear, power,majority, chair,seniority, nokken_poole_dim1, party_code, SenatorName, year, icpsr, log_miles,cong) %>% 
  dplyr::summarise(traveled = sum(traveled))
total$traveled[total$traveled>0]<-1
total$Republican[total$party_code!=200] <-0
total$Republican[total$party_code==200] <-1

reg1 <- felm(traveled ~ power + majority + chair + seniority + nokken_poole_dim1 + electionyear + Republican + log_miles | year | 0 | icpsr, data = total)
reg2 <- felm(traveled ~ power + majority + chair + seniority + nokken_poole_dim1 + electionyear | year + icpsr | 0 | icpsr, data = total)


selection <- stargazer(reg1, reg2,
                       add.lines=list(c("Year Fixed Effects","\\checkmark","\\checkmark"),
                                      c("Senator Fixed Effects","","\\checkmark")),
                       notes.append = FALSE, notes.label = "",
                       report="vc*s",star.char=c("*","**"),star.cutoffs = c(0.10,0.05),no.space = TRUE,
                       omit.stat = c("rsq", "ser","f"), font.size = "footnotesize",
                       dep.var.caption  = "Reports Per Diems",
                       dep.var.labels = "", model.numbers = FALSE,
                       column.labels=c("(1)","(2)"), align=TRUE,
                       covariate.labels=c("Power Committee", "Majority","Chair", "Seniority",
                                          "First Dim. Nokken-Poole Score", "Senator's Election Year","Republican", 
                                          "Logged State Square Miles"), 
                       notes="\\parbox[t]{.78\\textwidth}{\\footnotesize \\textit{Note}: Entries are linear regression coefficients with standard errors (clustered on senator) shown in parentheses. The dependent variable is a binary indicator of whether the senator reports any per diems. $^*$ indicates $p<0.10$ and $^{**} p<0.05$ (two tailed tests).}",
                       label="selection",
                       digits=3,
                       digits.extra = 0,
                       title="Predictors of Reporting Per Diems")
cat(selection, sep = '\n', file = "TableA1.tex")

########################################################
########################################################
# Policy Disagreement Appendix Results
########################################################
########################################################

#load the data
data <- read.dta13("complete_CCES_final.dta",convert.factors=FALSE)
data$race <- as.factor(as.character(data$race))
data <- data[!is.na(data$weight_cumulative),]
data$news_watch[data$newsint==1 | data$newsint==2] <-1
data$news_watch[data$newsint==3 | data$newsint==4 | data$newsint==7] <- 0

##################################
# Additional Vote Choice Results
##################################

data$dist <- data$traveledonce
reg1_vote <- felm(voted_for_inc ~ votematchmean2*(dist + copartisan + nokken_poole_dim1 + chair + power +  race + female + age) | member_county + party_year | 0 | icpsr, 
                  data = data, weights=data$weight_cumulative)

data$dist <- data$traveledonce_msa
reg1_msa_vote <- felm(voted_for_inc ~ votematchmean2*(dist + copartisan  + nokken_poole_dim1 + chair + power +  race + female + age) | member_msa + party_year | 0 | icpsr, 
                      data = data, weights=data$weight_cumulative)


data$dist <- data$traveled
reg3_vote <- felm(voted_for_inc ~ votematchmean2*(dist + copartisan + nokken_poole_dim1 + chair + power +  race + female + age) | member_county + party_year | 0 | icpsr, 
                  data = data, weights=data$weight_cumulative)

data$dist <- data$traveled_msa
reg3_msa_vote <- felm(voted_for_inc ~ votematchmean2*(dist + copartisan  + nokken_poole_dim1 + chair + power +  race + female + age) | member_msa + party_year | 0 | icpsr, 
                      data = data, weights=data$weight_cumulative)

data$dist <- data$staffeddonce
reg4_vote <- felm(voted_for_inc ~ votematchmean2*(dist + copartisan + nokken_poole_dim1 + chair + power +  race + female + age) | member_county + party_year | 0 | icpsr, 
                  data = data, weights=data$weight_cumulative)

data$dist <- data$staffeddonce_msa
reg4_msa_vote <- felm(voted_for_inc ~ votematchmean2*(dist + copartisan + nokken_poole_dim1 + chair + power +  race + female + age) | member_msa + party_year | 0 | icpsr, 
                      data = data, weights=data$weight_cumulative)

data$dist <- data$staff_per
reg6_vote <- felm(voted_for_inc ~ votematchmean2*(dist + copartisan + nokken_poole_dim1 + chair + power +  race + female + age) | member_county + party_year | 0 | icpsr, 
                  data = data, weights=data$weight_cumulative)

data$dist <- data$staff_per_msa
reg6_msa_vote <- felm(voted_for_inc ~ votematchmean2*(dist + copartisan + nokken_poole_dim1 + chair + power +  race + female + age) | member_msa + party_year | 0 | icpsr, 
                      data = data, weights=data$weight_cumulative)


visits_county_vote2 <- stargazer(reg1_vote, reg3_vote,reg4_vote,reg6_vote,
                                 omit=c("copartisan", "nokken_poole_dim1", "chair", "power",  "female", "race", "age"),
                                 add.lines=list(c("Senator-County Fixed Effects","\\checkmark","\\checkmark","\\checkmark","\\checkmark"),
                                                c("Party-Year Fixed Effects","\\checkmark","\\checkmark","\\checkmark","\\checkmark")),
                                 notes.append = FALSE, notes.label = "",
                                 report="vc*s",star.char=c("*","**"),star.cutoffs = c(0.10,0.05),no.space = TRUE,
                                 omit.stat = c("rsq", "ser","f"), font.size = "footnotesize",
                                 dep.var.caption  = "Dependent Variable: Vote for Incumbent (0/1)",
                                 dep.var.labels = "", model.numbers = FALSE,
                                 multicolumn = TRUE,
                                 column.labels=c("Any Visits", "Total Visits", "Any Staff", "Pct. of Staff"), align=TRUE,
                                 covariate.labels=c("Policy Disagreement", "Local Activity", "Policy Disagreement x Local Activity"),
                                 notes="\\parbox[t]{.9\\textwidth}{\\footnotesize \\textit{Note}: Entries are linear regression coefficients with standard errors (clustered on senator) shown in parentheses. The dependent variable is a binary measure of constituent vote choice. $^*$ indicates $p<0.10$ and $^{**} p<0.05$ (two tailed tests).}",
                                 label="linear_vote2",
                                 digits=3,
                                 digits.extra = 0,
                                 title="The Relationship between Local Attentiveness, Policy Representation, and Vote Choice")

visits_msa_vote2 <- stargazer(reg1_msa_vote,reg3_msa_vote,reg4_msa_vote,reg6_msa_vote, 
                              omit=c("copartisan", "nokken_poole_dim1", "chair", "power",  "female", "race", "age"),
                              add.lines=list(c("Senator-MSA Fixed Effects","\\checkmark","\\checkmark","\\checkmark","\\checkmark"),
                                             c("Party-Year Fixed Effects","\\checkmark","\\checkmark","\\checkmark","\\checkmark")),
                              notes.append = FALSE, notes.label = "",
                              report="vc*s",star.char=c("*","**"),star.cutoffs = c(0.10,0.05),no.space = TRUE,
                              omit.stat = c("rsq", "ser","f"), font.size = "footnotesize",
                              dep.var.caption  = "Dependent Variable: Vote for Incumbent (0/1)",
                              dep.var.labels ="", model.numbers = FALSE,
                              multicolumn = TRUE, 
                              column.labels=c("Any Visits", "Total Visits", "Any Staff", "Pct. of Staff"), align=TRUE,
                              covariate.labels=c("Policy Disagreement", "Local Activity", "Policy Disagreement x Local Activity"),
                              notes="\\parbox[t]{.9\\textwidth}{\\footnotesize \\textit{Note}: Entries are linear regression coefficients with standard errors (clustered on senator) shown in parentheses. The dependent variable is a binary measure of constituent vote choice. $^*$ indicates $p<0.10$ and $^{**} p<0.05$ (two tailed tests).}",
                              label="linear_vote2",
                              digits=3,
                              digits.extra = 0,
                              title="")
star.panel.out <- star_panel(visits_county_vote2, visits_msa_vote2, panel.label.fontface="bold",
                             panel.names = c("County", "Metropolitan Statistical Area"), same.summary.stats = FALSE)
cat(star.panel.out, sep = '\n', file = "TableF1.tex")


####################################
# Vote Split by Copartisan Status
####################################

#split by copartisan status
data_copartisans <- data[data$copartisan==1,]
data_copartisans <- data_copartisans[!is.na(data_copartisans$weight_cumulative),]
names(data_copartisans)[names(data_copartisans) == "voted_for_inc"] <- "voted_for_inc_co"

data_noncopartisans <- data[data$copartisan==0,]
data_noncopartisans <- data_noncopartisans[!is.na(data_noncopartisans$weight_cumulative),]


data_copartisans$dist <- data_copartisans$log_traveled
reg2_co <- felm(voted_for_inc_co ~ votematchmean2*(dist + nokken_poole_dim1 + chair + power +  race + female + age) | member_county + party_year | 0 | icpsr, 
                data = data_copartisans, weights=data_copartisans$weight_cumulative)

data_copartisans$dist <- data_copartisans$log_traveled_msa
reg2_msa_co <- felm(voted_for_inc_co ~ votematchmean2*(dist + nokken_poole_dim1 + chair + power +  race + female + age) | member_msa + party_year | 0 | icpsr, 
                    data = data_copartisans, weights=data_copartisans$weight_cumulative)

data_copartisans$dist <- data_copartisans$log_staffed
reg5_co <- felm(voted_for_inc_co ~ votematchmean2*(dist + nokken_poole_dim1 + chair + power +  race + female + age) | member_county + party_year | 0 | icpsr, 
                data = data_copartisans, weights=data_copartisans$weight_cumulative)

data_copartisans$dist <- data_copartisans$log_staffed_msa
reg5_msa_co <- felm(voted_for_inc_co ~ votematchmean2*(dist + nokken_poole_dim1 + chair + power +  race + female + age) | member_msa + party_year | 0 | icpsr, 
                    data = data_copartisans, weights=data_copartisans$weight_cumulative)


data_noncopartisans$dist <- data_noncopartisans$log_traveled
reg2_noco <- felm(voted_for_inc ~ votematchmean2*(dist + nokken_poole_dim1 + chair + power +  race + female + age) | member_county + party_year | 0 | icpsr, 
                  data = data_noncopartisans, weights=data_noncopartisans$weight_cumulative)

data_noncopartisans$dist <- data_noncopartisans$log_traveled_msa
reg2_msa_noco <- felm(voted_for_inc ~ votematchmean2*(dist + nokken_poole_dim1 + chair + power +  race + female + age) | member_msa + party_year | 0 | icpsr, 
                      data = data_noncopartisans, weights=data_noncopartisans$weight_cumulative)

data_noncopartisans$dist <- data_noncopartisans$log_staffed
reg5_noco <- felm(voted_for_inc ~ votematchmean2*(dist + nokken_poole_dim1 + chair + power +  race + female + age) | member_county + party_year | 0 | icpsr, 
                  data = data_noncopartisans, weights=data_noncopartisans$weight_cumulative)

data_noncopartisans$dist <- data_noncopartisans$log_staffed_msa
reg5_msa_noco <- felm(voted_for_inc ~ votematchmean2*(dist + nokken_poole_dim1 + chair + power +  race + female + age) | member_msa + party_year | 0 | icpsr, 
                      data = data_noncopartisans, weights=data_noncopartisans$weight_cumulative)



visits_county_co <- stargazer(reg2_co, reg5_co, reg2_noco, reg5_noco, 
                              omit=c("nokken_poole_dim1", "chair", "power",  "female", "race", "age"),
                              add.lines=list(c("Senator-County Fixed Effects","\\checkmark","\\checkmark","\\checkmark","\\checkmark"),
                                             c("Party-Year Fixed Effects","\\checkmark","\\checkmark","\\checkmark","\\checkmark")),
                              notes.append = FALSE, notes.label = "",
                              report="vc*s",star.char=c("*","**"),star.cutoffs = c(0.10,0.05),no.space = TRUE,
                              omit.stat = c("rsq", "ser","f"), font.size = "footnotesize",
                              dep.var.caption  = "Dependent Variable: Vote for Incumbent (0/1)",
                              dep.var.labels = c("Copartisans", "Non-Copartisans"), model.numbers = FALSE,
                              multicolumn = TRUE,
                              column.labels=c("ln(Visits + 1)", "ln(Pct. of Staff + 1)","ln(Visits + 1)", "ln(Pct. of Staff + 1)"), align=TRUE,
                              covariate.labels=c("Policy Disagreement", "Local Activity", "Policy Disagreement x Local Activity"),
                              notes="\\parbox[t]{\\textwidth}{\\footnotesize \\textit{Note}: Entries are linear regression coefficients with standard errors (clustered on senator) shown in parentheses. The dependent variable is a binary measure of constituent vote choice. $^*$ indicates $p<0.10$ and $^{**} p<0.05$ (two tailed tests).}",
                              label="linear_co",
                              digits=3,
                              digits.extra = 0,
                              title="The Relationship between Local Attentiveness, Policy Representation, and Vote Choice, Subset by Copartisan Status")

visits_msa_co <- stargazer(reg2_msa_co, reg5_msa_co, reg2_msa_noco, reg5_msa_noco,
                           omit=c( "nokken_poole_dim1", "chair", "power",  "female", "race", "age"),
                           add.lines=list(c("Senator-MSA Fixed Effects","\\checkmark","\\checkmark","\\checkmark","\\checkmark"),
                                          c("Party-Year Fixed Effects","\\checkmark","\\checkmark","\\checkmark","\\checkmark")),
                           notes.append = FALSE, notes.label = "",
                           report="vc*s",star.char=c("*","**"),star.cutoffs = c(0.10,0.05),no.space = TRUE,
                           omit.stat = c("rsq", "ser","f"), font.size = "footnotesize",
                           dep.var.caption  = "Dependent Variable: Vote for Incumbent ",
                           dep.var.labels = c("Copartisans", "Non-Copartisans"), model.numbers = FALSE,
                           multicolumn = TRUE, 
                           column.labels=c("ln(Visits + 1)", "ln(Pct. of Staff + 1)"), align=TRUE,
                           covariate.labels=c("Policy Disagreement", "Local Activity", "Policy Disagreement x Local Activity"),
                           notes="\\parbox[t]{\\textwidth}{\\footnotesize \\textit{Note}: Entries are linear regression coefficients with standard errors (clustered on senator) shown in parentheses. The dependent variable is a binary measure of constituent vote choice. $^*$ indicates $p<0.10$ and $^{**} p<0.05$ (two tailed tests).}",
                           label="linear_co",
                           digits=3,
                           digits.extra = 0,
                           title="")
star.panel.out <- star_panel(visits_county_co, visits_msa_co, panel.label.fontface="bold",
                             panel.names = c("County", "Metropolitan Statistical Area"), same.summary.stats = FALSE)
cat(star.panel.out, sep = '\n', file = "TableF2.tex")


####################################
# Excluding Not Sure from Approval
####################################

data_notsure <- data[data$approval!=5,]
#create a 4 point measure of approval in the correct direction - don't include 5, because that's don't know. 
data_notsure$approval2[data_notsure$approval==1] <- 4
data_notsure$approval2[data_notsure$approval==2] <- 3
data_notsure$approval2[data_notsure$approval==3] <- 2
data_notsure$approval2[data_notsure$approval==4] <- 1
data_notsure <- data_notsure[!is.na(data_notsure$weight_cumulative),]

# Visits: County level
data_notsure$dist <- data_notsure$traveledonce
reg1_notsure <- felm(approval_binary ~ votematchmean2*(dist + copartisan + electionyear + seniority + 
                                                         nokken_poole_dim1 + chair + power +  race + female + age) | member_county + party_year | 0 | icpsr, 
                     data = data_notsure, weights=data_notsure$weight_cumulative)

data_notsure$dist <- data_notsure$log_traveled
reg2_notsure <- felm(approval_binary ~ votematchmean2*(dist + copartisan + electionyear + seniority + 
                                                         nokken_poole_dim1 + chair + power +  race + female + age) | member_county + party_year | 0 | icpsr, 
                     data = data_notsure, weights=data_notsure$weight_cumulative)

data_notsure$dist <- data_notsure$traveled
reg3_notsure <- felm(approval_binary ~ votematchmean2*(dist + copartisan + electionyear + seniority + 
                                                         nokken_poole_dim1 + chair + power +  race + female + age) | member_county + party_year | 0 | icpsr, 
                     data = data_notsure, weights=data_notsure$weight_cumulative)

# Visits: MSA level
data_notsure$dist <- data_notsure$traveledonce_msa
reg1_msa_notsure <- felm(approval_binary ~ votematchmean2*(dist + copartisan + electionyear + seniority + 
                                                             nokken_poole_dim1 + chair + power +  race + female + age) | member_msa + party_year | 0 | icpsr, 
                         data = data_notsure, weights=data_notsure$weight_cumulative)

data_notsure$dist <- data_notsure$log_traveled_msa
reg2_msa_notsure <- felm(approval_binary ~ votematchmean2*(dist + copartisan + electionyear + seniority + 
                                                             nokken_poole_dim1 + chair + power +  race + female + age) | member_msa + party_year | 0 | icpsr, 
                         data = data_notsure, weights=data_notsure$weight_cumulative)

data_notsure$dist <- data_notsure$traveled_msa
reg3_msa_notsure <- felm(approval_binary ~ votematchmean2*(dist + copartisan + electionyear + seniority + 
                                                             nokken_poole_dim1 + chair + power +  race + female + age) | member_msa + party_year | 0 | icpsr, 
                         data = data_notsure, weights=data_notsure$weight_cumulative)


# Staff: County level
data_notsure$dist <- data_notsure$staffeddonce
reg4_notsure <- felm(approval_binary ~ votematchmean2*(dist + copartisan + electionyear + seniority + 
                                                         nokken_poole_dim1 + chair + power +  race + female + age) | member_county + party_year | 0 | icpsr, 
                     data = data_notsure, weights=data_notsure$weight_cumulative)

data_notsure$dist <- data_notsure$log_staffed
reg5_notsure <- felm(approval_binary ~ votematchmean2*(dist + copartisan + electionyear + seniority + 
                                                         nokken_poole_dim1 + chair + power +  race + female + age) | member_county + party_year | 0 | icpsr, 
                     data = data_notsure, weights=data_notsure$weight_cumulative)

data_notsure$dist <- data_notsure$staff_per
reg6_notsure <- felm(approval_binary ~ votematchmean2*(dist + copartisan + electionyear + seniority + 
                                                         nokken_poole_dim1 + chair + power +  race + female + age) | member_county + party_year | 0 | icpsr, 
                     data = data_notsure, weights=data_notsure$weight_cumulative)

# Staff: MSA level
data_notsure$dist <- data_notsure$staffeddonce_msa
reg4_msa_notsure <- felm(approval_binary ~ votematchmean2*(dist + copartisan + electionyear + seniority + 
                                                             nokken_poole_dim1 + chair + power +  race + female + age) | member_msa + party_year | 0 | icpsr, 
                         data = data_notsure, weights=data_notsure$weight_cumulative)

data_notsure$dist <- data_notsure$log_staffed_msa
reg5_msa_notsure <- felm(approval_binary ~ votematchmean2*(dist + copartisan + electionyear + seniority + 
                                                             nokken_poole_dim1 + chair + power +  race + female + age) | member_msa + party_year | 0 | icpsr, 
                         data = data_notsure, weights=data_notsure$weight_cumulative)

data_notsure$dist <- data_notsure$staff_per_msa
reg6_msa_notsure <- felm(approval_binary ~ votematchmean2*(dist + copartisan + electionyear + seniority + 
                                                             nokken_poole_dim1 + chair + power +  race + female + age) | member_msa + party_year | 0 | icpsr, 
                         data = data_notsure, weights=data_notsure$weight_cumulative)


county_notsure <- stargazer(reg1_notsure, reg3_notsure,reg2_notsure, reg4_notsure, reg6_notsure, reg5_notsure, 
                            omit=c("copartisan", "electionyear", "seniority", "nokken_poole_dim1", "chair", "power",  "female", "race", "age"),
                            add.lines=list(c("Senator-County Fixed Effects","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark"),
                                           c("Party-Year Fixed Effects","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark")),
                            notes.append = FALSE, notes.label = "",
                            report="vc*s",star.char=c("*","**"),star.cutoffs = c(0.10,0.05),no.space = TRUE,
                            omit.stat = c("rsq", "ser","f"), font.size = "footnotesize",
                            dep.var.caption  = "Dependent Variable: Approval (0/1)",
                            dep.var.labels = "", model.numbers = FALSE,
                            column.labels=c("Any Visits", "Total Visits","ln(Visits + 1)","Any Staff", "Pct. Staff","ln(Pct. of Staff + 1)"), align=TRUE,
                            covariate.labels=c("Policy Disagreement", "Local Activity", "Policy Disagreement x Local Activity"),
                            notes="\\parbox[t]{1.05\\textwidth}{\\footnotesize \\textit{Note}: Entries are linear regression coefficients with standard errors (clustered on senator) shown in parentheses. The dependent variable is a binary measure of constituent approval. $^*$ indicates $p<0.10$ and $^{**} p<0.05$ (two tailed tests).}",
                            label="linear_notsure",
                            digits=3, column.sep.width = "-9pt", 
                            digits.extra = 0,
                            title="The Relationship between Local Attentiveness, Policy Representation, and Approval Excluding ``Not Sure''")

msa_notsure <- stargazer(reg1_msa_notsure, reg3_msa_notsure,reg2_msa_notsure, reg4_msa_notsure, reg6_msa_notsure, reg5_msa_notsure,
                         omit=c("copartisan", "electionyear", "seniority", "nokken_poole_dim1", "chair", "power",  "female", "race", "age"),
                         add.lines=list(c("Senator-MSA Fixed Effects","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark"),
                                        c("Party-Year Fixed Effects","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark")),
                         notes.append = FALSE, notes.label = "",
                         report="vc*s",star.char=c("*","**"),star.cutoffs = c(0.10,0.05),no.space = TRUE,
                         omit.stat = c("rsq", "ser","f"), font.size = "footnotesize",
                         dep.var.caption  = "Dependent Variable: Approval (0/1)",
                         dep.var.labels = "", model.numbers = FALSE,
                         column.labels=c("Any Visits", "Total Visits","ln(Visits + 1)","Any Staff", "Pct. Staff","ln(Pct. of Staff + 1)"), align=TRUE,
                         covariate.labels=c("Policy Disagreement", "Local Activity", "Policy Disagreement x Local Activity"),
                         notes="\\parbox[t]{1.05\\textwidth}{\\footnotesize \\textit{Note}: Entries are linear regression coefficients with standard errors (clustered on senator) shown in parentheses. The dependent variable is a binary measure of constituent approval. $^*$ indicates $p<0.10$ and $^{**} p<0.05$ (two tailed tests).}",
                         label="linear_notsure",
                         digits=3,
                         digits.extra = 0,column.sep.width = "-9pt", 
                         title="")
star.panel.out <- star_panel(county_notsure, msa_notsure,panel.label.fontface="bold",
                             panel.names = c("County", "Metropolitan Statistical Area"), same.summary.stats = FALSE)
cat(star.panel.out, sep = '\n', file = "TableE1.tex")


#################################
# 4 Point Measure of Approval
#################################

# Visits: County level
data_notsure$dist <- data_notsure$traveledonce
reg1_4point <- felm(approval2 ~ votematchmean2*(dist + copartisan + electionyear + seniority + 
                                                  nokken_poole_dim1 + chair + power +  race + female + age) | member_county + party_year | 0 | icpsr, 
                    data = data_notsure, weights=data_notsure$weight_cumulative)

data_notsure$dist <- data_notsure$log_traveled
reg2_4point <- felm(approval2 ~ votematchmean2*(dist + copartisan + electionyear + seniority + 
                                                  nokken_poole_dim1 + chair + power +  race + female + age) | member_county + party_year | 0 | icpsr, 
                    data = data_notsure, weights=data_notsure$weight_cumulative)

data_notsure$dist <- data_notsure$traveled
reg3_4point <- felm(approval2 ~ votematchmean2*(dist + copartisan + electionyear + seniority + 
                                                  nokken_poole_dim1 + chair + power +  race + female + age) | member_county + party_year | 0 | icpsr, 
                    data = data_notsure, weights=data_notsure$weight_cumulative)

# Visits: MSA level
data_notsure$dist <- data_notsure$traveledonce_msa
reg1_msa_4point <- felm(approval2 ~ votematchmean2*(dist + copartisan + electionyear + seniority + 
                                                      nokken_poole_dim1 + chair + power +  race + female + age) | member_msa + party_year | 0 | icpsr, 
                        data = data_notsure, weights=data_notsure$weight_cumulative)

data_notsure$dist <- data_notsure$log_traveled_msa
reg2_msa_4point <- felm(approval2 ~ votematchmean2*(dist + copartisan + electionyear + seniority + 
                                                      nokken_poole_dim1 + chair + power +  race + female + age) | member_msa + party_year | 0 | icpsr, 
                        data = data_notsure, weights=data_notsure$weight_cumulative)

data_notsure$dist <- data_notsure$traveled_msa
reg3_msa_4point <- felm(approval2 ~ votematchmean2*(dist + copartisan + electionyear + seniority + 
                                                      nokken_poole_dim1 + chair + power +  race + female + age) | member_msa + party_year | 0 | icpsr, 
                        data = data_notsure, weights=data_notsure$weight_cumulative)


# Staff: County level
data_notsure$dist <- data_notsure$staffeddonce
reg4_4point <- felm(approval2 ~ votematchmean2*(dist + copartisan + electionyear + seniority + 
                                                  nokken_poole_dim1 + chair + power +  race + female + age) | member_county + party_year | 0 | icpsr, 
                    data = data_notsure, weights=data_notsure$weight_cumulative)

data_notsure$dist <- data_notsure$log_staffed
reg5_4point <- felm(approval2 ~ votematchmean2*(dist + copartisan + electionyear + seniority + 
                                                  nokken_poole_dim1 + chair + power +  race + female + age) | member_county + party_year | 0 | icpsr, 
                    data = data_notsure, weights=data_notsure$weight_cumulative)

data_notsure$dist <- data_notsure$staff_per
reg6_4point <- felm(approval2 ~ votematchmean2*(dist + copartisan + electionyear + seniority + 
                                                  nokken_poole_dim1 + chair + power +  race + female + age) | member_county + party_year | 0 | icpsr, 
                    data = data_notsure, weights=data_notsure$weight_cumulative)

# Staff: MSA level
data_notsure$dist <- data_notsure$staffeddonce_msa
reg4_msa_4point <- felm(approval2 ~ votematchmean2*(dist + copartisan + electionyear + seniority + 
                                                      nokken_poole_dim1 + chair + power +  race + female + age) | member_msa + party_year | 0 | icpsr, 
                        data = data_notsure, weights=data_notsure$weight_cumulative)

data_notsure$dist <- data_notsure$log_staffed_msa
reg5_msa_4point <- felm(approval2 ~ votematchmean2*(dist + copartisan + electionyear + seniority + 
                                                      nokken_poole_dim1 + chair + power +  race + female + age) | member_msa + party_year | 0 | icpsr, 
                        data = data_notsure, weights=data_notsure$weight_cumulative)

data_notsure$dist <- data_notsure$staff_per_msa
reg6_msa_4point <- felm(approval2 ~ votematchmean2*(dist + copartisan + electionyear + seniority + 
                                                      nokken_poole_dim1 + chair + power +  race + female + age) | member_msa + party_year | 0 | icpsr, 
                        data = data_notsure, weights=data_notsure$weight_cumulative)


county_4point <- stargazer(reg1_4point, reg3_4point,reg2_4point, reg4_4point, reg6_4point, reg5_4point, 
                           omit=c("copartisan", "electionyear", "seniority", "nokken_poole_dim1", "chair", "power",  "female", "race", "age"),
                           add.lines=list(c("Senator-County Fixed Effects","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark"),
                                          c("Party-Year Fixed Effects","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark")),
                           notes.append = FALSE, notes.label = "",
                           report="vc*s",star.char=c("*","**"),star.cutoffs = c(0.10,0.05),no.space = TRUE,
                           omit.stat = c("rsq", "ser","f"), font.size = "footnotesize",
                           dep.var.caption  = "Dependent Variable: Approval (0/1)",
                           dep.var.labels = "", model.numbers = FALSE,
                           column.labels=c("Any Visits", "Total Visits","ln(Visits + 1)","Any Staff", "Pct. Staff","ln(Pct. of Staff + 1)"), align=TRUE,
                           covariate.labels=c("Policy Disagreement", "Local Activity", "Policy Disagreement x Local Activity"),
                           notes="\\parbox[t]{1.05\\textwidth}{\\footnotesize \\textit{Note}: Entries are linear regression coefficients with standard errors (clustered on senator) shown in parentheses. The dependent variable is a 4-point measure of constituent approval. $^*$ indicates $p<0.10$ and $^{**} p<0.05$ (two tailed tests).}",
                           label="linear_4point",
                           digits=3, column.sep.width = "-9pt", 
                           digits.extra = 0,
                           title="The Relationship between Local Attentiveness, Policy Representation, and Approval Using a 4-Point Measure of Approval")

msa_4point <- stargazer(reg1_msa_4point, reg3_msa_4point,reg2_msa_4point, reg4_msa_4point, reg6_msa_4point, reg5_msa_4point,
                        omit=c("copartisan", "electionyear", "seniority", "nokken_poole_dim1", "chair", "power",  "female", "race", "age"),
                        add.lines=list(c("Senator-MSA Fixed Effects","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark"),
                                       c("Party-Year Fixed Effects","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark")),
                        notes.append = FALSE, notes.label = "",
                        report="vc*s",star.char=c("*","**"),star.cutoffs = c(0.10,0.05),no.space = TRUE,
                        omit.stat = c("rsq", "ser","f"), font.size = "footnotesize",
                        dep.var.caption  = "Dependent Variable: Approval (0/1)",
                        dep.var.labels = "", model.numbers = FALSE,
                        column.labels=c("Any Visits", "Total Visits","ln(Visits + 1)","Any Staff", "Pct. Staff","ln(Pct. of Staff + 1)"), align=TRUE,
                        covariate.labels=c("Policy Disagreement", "Local Activity", "Policy Disagreement x Local Activity"),
                        notes="\\parbox[t]{1.05\\textwidth}{\\footnotesize \\textit{Note}: Entries are linear regression coefficients with standard errors (clustered on senator) shown in parentheses. The dependent variable is a 4-point measure of constituent approval. $^*$ indicates $p<0.10$ and $^{**} p<0.05$ (two tailed tests).}",
                        label="linear_4point",
                        digits=3,
                        digits.extra = 0,column.sep.width = "-9pt", 
                        title="")
star.panel.out <- star_panel(county_4point, msa_4point,panel.label.fontface="bold",
                             panel.names = c("County", "Metropolitan Statistical Area"), same.summary.stats = FALSE)
cat(star.panel.out, sep = '\n', file = "TableE2.tex")

##########################################################
# Excluding States with Ten Counties or Less
##########################################################

data_noten <- data[data$stateabrev!="NH" & data$stateabrev!="CT" & data$stateabrev!="HI" & data$stateabrev!="RI" & data$stateabrev!="DE",]

# Visits: County level
data_noten$dist <- data_noten$traveledonce
reg1_noten <- felm(approval_binary ~ votematchmean2*(dist + copartisan + electionyear + seniority + 
                                                       nokken_poole_dim1 + chair + power +  race + female + age) | member_county + party_year | 0 | icpsr, 
                   data = data_noten, weights=data_noten$weight_cumulative)

data_noten$dist <- data_noten$log_traveled
reg2_noten <- felm(approval_binary ~ votematchmean2*(dist + copartisan + electionyear + seniority + 
                                                       nokken_poole_dim1 + chair + power +  race + female + age) | member_county + party_year | 0 | icpsr, 
                   data = data_noten, weights=data_noten$weight_cumulative)

data_noten$dist <- data_noten$traveled
reg3_noten <- felm(approval_binary ~ votematchmean2*(dist + copartisan + electionyear + seniority + 
                                                       nokken_poole_dim1 + chair + power +  race + female + age) | member_county + party_year | 0 | icpsr, 
                   data = data_noten, weights=data_noten$weight_cumulative)

# Visits: MSA level
data_noten$dist <- data_noten$traveledonce_msa
reg1_msa_noten <- felm(approval_binary ~ votematchmean2*(dist  + copartisan + electionyear + seniority + 
                                                           nokken_poole_dim1 + chair + power +  race + female + age) | member_msa + party_year | 0 | icpsr, 
                       data = data_noten, weights=data_noten$weight_cumulative)

data_noten$dist <- data_noten$log_traveled_msa
reg2_msa_noten <- felm(approval_binary ~ votematchmean2*(dist  + copartisan + electionyear + seniority + 
                                                           nokken_poole_dim1 + chair + power +  race + female + age) | member_msa + party_year | 0 | icpsr, 
                       data = data_noten, weights=data_noten$weight_cumulative)

data_noten$dist  <- data_noten$traveled_msa
reg3_msa_noten <- felm(approval_binary ~ votematchmean2*(dist  + copartisan + electionyear + seniority + 
                                                           nokken_poole_dim1 + chair + power +  race + female + age) | member_msa + party_year | 0 | icpsr, 
                       data = data_noten, weights=data_noten$weight_cumulative)

# Staff: County level
data_noten$dist <- data_noten$staffeddonce
reg4_noten <- felm(approval_binary ~ votematchmean2*(dist + copartisan + electionyear + seniority + 
                                                       nokken_poole_dim1 + chair + power +  race + female + age) | member_county + party_year | 0 | icpsr, 
                   data = data_noten, weights=data_noten$weight_cumulative)

data_noten$dist <- data_noten$log_staffed
reg5_noten <- felm(approval_binary ~ votematchmean2*(dist + copartisan + electionyear + seniority + 
                                                       nokken_poole_dim1 + chair + power +  race + female + age) | member_county + party_year | 0 | icpsr, 
                   data = data_noten, weights=data_noten$weight_cumulative)

data_noten$dist <- data_noten$staff_per
reg6_noten <- felm(approval_binary ~ votematchmean2*(dist + copartisan + electionyear + seniority + 
                                                       nokken_poole_dim1 + chair + power +  race + female + age) | member_county + party_year | 0 | icpsr, 
                   data = data_noten, weights=data_noten$weight_cumulative)

# Staff: MSA level
data_noten$dist <- data_noten$staffeddonce_msa
reg4_msa_noten <- felm(approval_binary ~ votematchmean2*(dist  + copartisan + electionyear + seniority + 
                                                           nokken_poole_dim1 + chair + power +  race + female + age) | member_msa + party_year | 0 | icpsr, 
                       data = data_noten, weights=data_noten$weight_cumulative)

data_noten$dist <- data_noten$log_staffed_msa
reg5_msa_noten <- felm(approval_binary ~ votematchmean2*(dist  + copartisan + electionyear + seniority + 
                                                           nokken_poole_dim1 + chair + power +  race + female + age) | member_msa + party_year | 0 | icpsr, 
                       data = data_noten, weights=data_noten$weight_cumulative)

data_noten$dist  <- data_noten$staff_per_msa
reg6_msa_noten <- felm(approval_binary ~ votematchmean2*(dist  + copartisan + electionyear + seniority + 
                                                           nokken_poole_dim1 + chair + power +  race + female + age) | member_msa + party_year | 0 | icpsr, 
                       data = data_noten, weights=data_noten$weight_cumulative)


county_noten <- stargazer(reg1_noten, reg3_noten,reg2_noten, reg4_noten, reg6_noten, reg5_noten, 
                          omit=c("copartisan", "electionyear", "seniority", "nokken_poole_dim1", "chair", "power",  "female", "race", "age"),
                          add.lines=list(c("Senator-County Fixed Effects","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark"),
                                         c("Party-Year Fixed Effects","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark")),
                          notes.append = FALSE, notes.label = "",
                          report="vc*s",star.char=c("*","**"),star.cutoffs = c(0.10,0.05),no.space = TRUE,
                          omit.stat = c("rsq", "ser","f"), font.size = "footnotesize",
                          dep.var.caption  = "Dependent Variable: Approval (0/1)",
                          dep.var.labels = "", model.numbers = FALSE,
                          column.labels=c("Any Visits", "Total Visits","ln(Visits + 1)","Any Staff", "Pct. Staff","ln(Pct. of Staff + 1)"), align=TRUE,
                          covariate.labels=c("Policy Disagreement", "Local Activity", "Policy Disagreement x Local Activity"),
                          notes="\\parbox[t]{1.05\\textwidth}{\\footnotesize \\textit{Note}: Entries are linear regression coefficients with standard errors (clustered on senator) shown in parentheses. The dependent variable is a binary measure of constituent approval. $^*$ indicates $p<0.10$ and $^{**} p<0.05$ (two tailed tests).}",
                          label="linear_noten",
                          digits=3, column.sep.width = "-9pt", 
                          digits.extra = 0,
                          title="The Relationship between Local Attentiveness, Policy Representation, and Approval Excluding States with Ten Counties or Less")

msa_noten <- stargazer(reg1_msa_noten, reg3_msa_noten,reg2_msa_noten, reg4_msa_noten, reg6_msa_noten, reg5_msa_noten,
                       omit=c("copartisan", "electionyear", "seniority", "nokken_poole_dim1", "chair", "power",  "female", "race", "age"),
                       add.lines=list(c("Senator-MSA Fixed Effects","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark"),
                                      c("Party-Year Fixed Effects","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark")),
                       notes.append = FALSE, notes.label = "",
                       report="vc*s",star.char=c("*","**"),star.cutoffs = c(0.10,0.05),no.space = TRUE,
                       omit.stat = c("rsq", "ser","f"), font.size = "footnotesize",
                       dep.var.caption  = "Dependent Variable: Approval (0/1)",
                       dep.var.labels = "", model.numbers = FALSE,
                       column.labels=c("Any Visits", "Total Visits","ln(Visits + 1)","Any Staff", "Pct. Staff","ln(Pct. of Staff + 1)"), align=TRUE,
                       covariate.labels=c("Policy Disagreement", "Local Activity", "Policy Disagreement x Local Activity"),
                       notes="\\parbox[t]{1.05\\textwidth}{\\footnotesize \\textit{Note}: Entries are linear regression coefficients with standard errors (clustered on senator) shown in parentheses. The dependent variable is a binary measure of constituent approval. $^*$ indicates $p<0.10$ and $^{**} p<0.05$ (two tailed tests).}",
                       label="linear_noten",
                       digits=3,
                       digits.extra = 0,column.sep.width = "-9pt", 
                       title="")
star.panel.out <- star_panel(county_noten, msa_noten,panel.label.fontface="bold",
                             panel.names = c("County", "Metropolitan Statistical Area"), same.summary.stats = FALSE)
cat(star.panel.out, sep = '\n', file = "TableE3.tex")

##########################################################
# Excluding Maryland and Virginia
##########################################################

data_noclose <- data[data$stateabrev!="MD" & data$stateabrev!="VA",]

# Visits: County Level
data_noclose$dist <- data_noclose$traveledonce
reg1_noclose <- felm(approval_binary ~ votematchmean2*(dist + copartisan + electionyear + seniority + 
                                                         nokken_poole_dim1 + chair + power +  race + female + age) | member_county + party_year | 0 | icpsr, 
                     data = data_noclose, weights=data_noclose$weight_cumulative)

data_noclose$dist <- data_noclose$log_traveled
reg2_noclose <- felm(approval_binary ~ votematchmean2*(dist+ copartisan + electionyear + seniority + 
                                                         nokken_poole_dim1 + chair + power +  race + female + age) | member_county + party_year | 0 | icpsr, 
                     data = data_noclose, weights=data_noclose$weight_cumulative)

data_noclose$dist <- data_noclose$traveled
reg3_noclose <- felm(approval_binary ~ votematchmean2*(dist + copartisan + electionyear + seniority + 
                                                         nokken_poole_dim1 + chair + power +  race + female + age) | member_county + party_year | 0 | icpsr, 
                     data = data_noclose, weights=data_noclose$weight_cumulative)

# Visits: MSA Level
data_noclose$dist <- data_noclose$traveledonce_msa
reg1_msa_noclose <- felm(approval_binary ~ votematchmean2*(dist + copartisan + electionyear + seniority + 
                                                             nokken_poole_dim1 + chair + power +  race + female + age) | member_msa + party_year | 0 | icpsr, 
                         data = data_noclose, weights=data_noclose$weight_cumulative)

data_noclose$dist <- data_noclose$log_traveled_msa
reg2_msa_noclose <- felm(approval_binary ~ votematchmean2*(dist + copartisan + electionyear + seniority + 
                                                             nokken_poole_dim1 + chair + power +  race + female + age) | member_msa + party_year | 0 | icpsr, 
                         data = data_noclose, weights=data_noclose$weight_cumulative)

data_noclose$dist <- data_noclose$traveled_msa
reg3_msa_noclose <- felm(approval_binary ~ votematchmean2*(dist + copartisan + electionyear + seniority + 
                                                             nokken_poole_dim1 + chair + power +  race + female + age) | member_msa + party_year | 0 | icpsr, 
                         data = data_noclose, weights=data_noclose$weight_cumulative)

# Staff: County Level
data_noclose$dist <- data_noclose$staffeddonce
reg4_noclose <- felm(approval_binary ~ votematchmean2*(dist + copartisan + electionyear + seniority + 
                                                         nokken_poole_dim1 + chair + power +  race + female + age) | member_county + party_year | 0 | icpsr, 
                     data = data_noclose, weights=data_noclose$weight_cumulative)

data_noclose$dist <- data_noclose$log_staffed
reg5_noclose <- felm(approval_binary ~ votematchmean2*(dist+ copartisan + electionyear + seniority + 
                                                         nokken_poole_dim1 + chair + power +  race + female + age) | member_county + party_year | 0 | icpsr, 
                     data = data_noclose, weights=data_noclose$weight_cumulative)

data_noclose$dist <- data_noclose$staff_per
reg6_noclose <- felm(approval_binary ~ votematchmean2*(dist + copartisan + electionyear + seniority + 
                                                         nokken_poole_dim1 + chair + power +  race + female + age) | member_county + party_year | 0 | icpsr, 
                     data = data_noclose, weights=data_noclose$weight_cumulative)

# Staff: MSA Level
data_noclose$dist <- data_noclose$staffeddonce_msa
reg4_msa_noclose <- felm(approval_binary ~ votematchmean2*(dist + copartisan + electionyear + seniority + 
                                                             nokken_poole_dim1 + chair + power +  race + female + age) | member_msa + party_year | 0 | icpsr, 
                         data = data_noclose, weights=data_noclose$weight_cumulative)

data_noclose$dist <- data_noclose$log_staffed_msa
reg5_msa_noclose <- felm(approval_binary ~ votematchmean2*(dist + copartisan + electionyear + seniority + 
                                                             nokken_poole_dim1 + chair + power +  race + female + age) | member_msa + party_year | 0 | icpsr, 
                         data = data_noclose, weights=data_noclose$weight_cumulative)

data_noclose$dist <- data_noclose$staff_per_msa
reg6_msa_noclose <- felm(approval_binary ~ votematchmean2*(dist + copartisan + electionyear + seniority + 
                                                             nokken_poole_dim1 + chair + power +  race + female + age) | member_msa + party_year | 0 | icpsr, 
                         data = data_noclose, weights=data_noclose$weight_cumulative)



county_noclose <- stargazer(reg1_noclose, reg3_noclose,reg2_noclose, reg4_noclose, reg6_noclose, reg5_noclose, 
                            omit=c("copartisan", "electionyear", "seniority", "nokken_poole_dim1", "chair", "power",  "female", "race", "age"),
                            add.lines=list(c("Senator-County Fixed Effects","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark"),
                                           c("Party-Year Fixed Effects","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark")),
                            notes.append = FALSE, notes.label = "",
                            report="vc*s",star.char=c("*","**"),star.cutoffs = c(0.10,0.05),no.space = TRUE,
                            omit.stat = c("rsq", "ser","f"), font.size = "footnotesize",
                            dep.var.caption  = "Dependent Variable: Approval (0/1)",
                            dep.var.labels = "", model.numbers = FALSE,
                            column.labels=c("Any Visits", "Total Visits","ln(Visits + 1)","Any Staff", "Pct. Staff","ln(Pct. of Staff + 1)"), align=TRUE,
                            covariate.labels=c("Policy Disagreement", "Local Activity", "Policy Disagreement x Local Activity"),
                            notes="\\parbox[t]{1.05\\textwidth}{\\footnotesize \\textit{Note}: Entries are linear regression coefficients with standard errors (clustered on senator) shown in parentheses. The dependent variable is a binary measure of constituent approval. $^*$ indicates $p<0.10$ and $^{**} p<0.05$ (two tailed tests).}",
                            label="linear_noclose",
                            digits=3, column.sep.width = "-9pt", 
                            digits.extra = 0,
                            title="The Relationship between Local Attentiveness, Policy Representation, and Approval Excluding Maryland and Virginia")

msa_noclose <- stargazer(reg1_msa_noclose, reg3_msa_noclose,reg2_msa_noclose, reg4_msa_noclose, reg6_msa_noclose, reg5_msa_noclose,
                         omit=c("copartisan", "electionyear", "seniority", "nokken_poole_dim1", "chair", "power",  "female", "race", "age"),
                         add.lines=list(c("Senator-MSA Fixed Effects","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark"),
                                        c("Party-Year Fixed Effects","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark","\\checkmark")),
                         notes.append = FALSE, notes.label = "",
                         report="vc*s",star.char=c("*","**"),star.cutoffs = c(0.10,0.05),no.space = TRUE,
                         omit.stat = c("rsq", "ser","f"), font.size = "footnotesize",
                         dep.var.caption  = "Dependent Variable: Approval (0/1)",
                         dep.var.labels = "", model.numbers = FALSE,
                         column.labels=c("Any Visits", "Total Visits","ln(Visits + 1)","Any Staff", "Pct. Staff","ln(Pct. of Staff + 1)"), align=TRUE,
                         covariate.labels=c("Policy Disagreement", "Local Activity", "Policy Disagreement x Local Activity"),
                         notes="\\parbox[t]{1.05\\textwidth}{\\footnotesize \\textit{Note}: Entries are linear regression coefficients with standard errors (clustered on senator) shown in parentheses. The dependent variable is a binary measure of constituent approval. $^*$ indicates $p<0.10$ and $^{**} p<0.05$ (two tailed tests).}",
                         label="linear_noclose",
                         digits=3,
                         digits.extra = 0,column.sep.width = "-9pt", 
                         title="")
star.panel.out <- star_panel(county_noclose, msa_noclose,panel.label.fontface="bold",
                             panel.names = c("County", "Metropolitan Statistical Area"), same.summary.stats = FALSE)
cat(star.panel.out, sep = '\n', file = "TableE4.tex")

############################################
#Total visits controlling for any visits
############################################

# Visits: County Level
data$dist <- data$traveled
data$dist2 <- data$traveledonce
reg_trav2 <- felm(approval_binary ~ votematchmean2*(dist + dist2 + copartisan + electionyear + seniority + 
                                                      nokken_poole_dim1 + chair + power +  race + female + age) | member_county + party_year | 0 | icpsr, 
                  data = data, weights=data$weight_cumulative)

# Visits: MSA Level
data$dist <- data$traveled_msa
data$dist2 <- data$traveledonce_msa
reg_msa_trav2 <- felm(approval_binary ~ votematchmean2*(dist + dist2 + copartisan + electionyear + seniority + 
                                                          nokken_poole_dim1 + chair + power +  race + female + age) | member_msa + party_year | 0 | icpsr, 
                      data = data, weights=data$weight_cumulative)

# Staff: County Level
data$dist <- data$staff_per
data$dist2 <- data$staffeddonce
reg_trav3 <- felm(approval_binary ~ votematchmean2*(dist + dist2 + copartisan + electionyear + seniority + 
                                                      nokken_poole_dim1 + chair + power +  race + female + age) | member_county + party_year | 0 | icpsr, 
                  data = data, weights=data$weight_cumulative)

# Staff: MSA Level
data$dist <- data$staff_per_msa
data$dist2 <- data$staffeddonce_msa
reg_msa_trav3 <- felm(approval_binary ~ votematchmean2*(dist + dist2 + copartisan + electionyear + seniority + 
                                                          nokken_poole_dim1 + chair + power +  race + female + age) | member_msa + party_year | 0 | icpsr, 
                      data = data, weights=data$weight_cumulative)

visits_county_trav2 <- stargazer(reg_trav2, reg_trav3,
                                 omit=c("copartisan", "electionyear", "seniority", "nokken_poole_dim1", "chair", "power",  "female", "race", "age"),
                                 add.lines=list(c("Senator-County Fixed Effects","\\checkmark","\\checkmark"),
                                                c("Party-Year Fixed Effects","\\checkmark","\\checkmark")),
                                 notes.append = FALSE, notes.label = "",
                                 report="vc*s",star.char=c("*","**"),star.cutoffs = c(0.10,0.05),no.space = TRUE,
                                 omit.stat = c("rsq", "ser","f"), font.size = "footnotesize",
                                 dep.var.caption  = "Dependent Variable: Approval (0/1)",
                                 dep.var.labels = "", model.numbers = FALSE,
                                 column.labels=c("Total Visits", "Total Staff"), align=TRUE,
                                 covariate.labels=c("Policy Disagreement", "Local Attentiveness", "Any Attentiveness", "Policy Disagreement x Local Attentiveness", "Policy Disagreement x Any Attentiveness"),
                                 notes="\\parbox[t]{.78\\textwidth}{\\footnotesize \\textit{Note}: Entries are linear regression coefficients with standard errors (clustered on senator) shown in parentheses. The dependent variable is a binary measure of constituent approval. $^*$ indicates $p<0.10$ and $^{**} p<0.05$ (two tailed tests).}",
                                 label="linear_trav2",
                                 digits=3,
                                 digits.extra = 0,
                                 title="The Relationship between Local Attentiveness, Policy Representation, and Approval Controlling for Any Attentiveness")

visits_msa_trav2 <- stargazer(reg_msa_trav2, reg_msa_trav3,
                              omit=c("copartisan", "electionyear", "seniority", "nokken_poole_dim1", "chair", "power",  "female", "race", "age"),
                              add.lines=list(c("Senator-MSA Fixed Effects","\\checkmark","\\checkmark"),
                                             c("Party-Year Fixed Effects","\\checkmark","\\checkmark")),
                              notes.append = FALSE, notes.label = "",
                              report="vc*s",star.char=c("*","**"),star.cutoffs = c(0.10,0.05),no.space = TRUE,
                              omit.stat = c("rsq", "ser","f"), font.size = "footnotesize",
                              dep.var.caption  = "Dependent Variable: Approval (0/1)",
                              dep.var.labels = "", model.numbers = FALSE,
                              column.labels=c("Total Visits", "Total Staff"), align=TRUE,
                              covariate.labels=c("Policy Disagreement", "Local Attentiveness", "Any Attentiveness", "Policy Disagreement x Local Attentiveness", "Policy Disagreement x Any Attentiveness"),
                              notes="\\parbox[t]{.78\\textwidth}{\\footnotesize \\textit{Note}: Entries are linear regression coefficients with standard errors (clustered on senator) shown in parentheses. The dependent variable is a binary measure of constituent approval. $^*$ indicates $p<0.10$ and $^{**} p<0.05$ (two tailed tests).}",
                              label="linear_trav2",
                              digits=3,
                              digits.extra = 0,
                              title="")


star.panel.out <- star_panel(visits_county_trav2, visits_msa_trav2,panel.label.fontface="bold",
                             panel.names = c("County", "Metropolitan Statistical Area"), same.summary.stats = FALSE)
cat(star.panel.out, sep = '\n', file = "TableE5.tex")


##############################
#Transportation receipts
##############################

# Visits: County Level
data$visits <- data$traveledonce_transportation
reg1_transportation <- felm(approval_binary ~ votematchmean2*(visits + copartisan + electionyear + seniority + 
                                                                nokken_poole_dim1 + chair + power +  race + female + age) | member_county + party_year | 0 | icpsr, 
                            data = data, weights=data$weight_cumulative)

data$visits <- data$log_traveled_transportation
reg2_transportation <- felm(approval_binary ~ votematchmean2*(visits + copartisan + electionyear + seniority + 
                                                                nokken_poole_dim1 + chair + power +  race + female + age) | member_county + party_year | 0 | icpsr, 
                            data = data, weights=data$weight_cumulative)

data$visits <- data$traveled_transportation
reg3_transportation <- felm(approval_binary ~ votematchmean2*(visits + copartisan + electionyear + seniority + 
                                                                nokken_poole_dim1 + chair + power +  race + female + age) | member_county + party_year | 0 | icpsr, 
                            data = data, weights=data$weight_cumulative)

# Visits: MSA Level
data$visits <- data$traveledonce_transpo_msa
reg1_msa_transportation <- felm(approval_binary ~ votematchmean2*(visits + copartisan + electionyear + seniority + 
                                                                    nokken_poole_dim1 + chair + power +  race + female + age) | member_msa + party_year | 0 | icpsr, 
                                data = data, weights=data$weight_cumulative)

data$visits <- data$log_traveled_transpo_msa
reg2_msa_transportation <- felm(approval_binary ~ votematchmean2*(visits + copartisan + electionyear + seniority + 
                                                                    nokken_poole_dim1 + chair + power +  race + female + age) | member_msa + party_year | 0 | icpsr, 
                                data = data, weights=data$weight_cumulative)

data$visits <- data$traveled_transpo_msa
reg3_msa_transportation <- felm(approval_binary ~ votematchmean2*(visits + copartisan + electionyear + seniority + 
                                                                    nokken_poole_dim1 + chair + power +  race + female + age) | member_msa + party_year | 0 | icpsr, 
                                data = data, weights=data$weight_cumulative)

visits_county_transportation <- stargazer(reg1_transportation,  reg3_transportation,reg2_transportation,
                                          omit=c("copartisan", "electionyear", "seniority", "nokken_poole_dim1", "chair", "power",  "female", "race", "age"),
                                          add.lines=list(c("Senator-County Fixed Effects","\\checkmark","\\checkmark","\\checkmark"),
                                                         c("Party-Year Fixed Effects","\\checkmark","\\checkmark","\\checkmark")),
                                          notes.append = FALSE, notes.label = "",
                                          report="vc*s",star.char=c("*","**"),star.cutoffs = c(0.10,0.05),no.space = TRUE,
                                          omit.stat = c("rsq", "ser","f"), font.size = "footnotesize",
                                          dep.var.caption  = "Dependent Variable: Approval (0/1)",
                                          dep.var.labels = "", model.numbers = FALSE,
                                          column.labels=c("Any Visits", "Total Visits","ln(Visits + 1)"), align=TRUE,
                                          covariate.labels=c("Policy Disagreement", "Visits", "Policy Disagreement x Visits"),
                                          notes="\\parbox[t]{.78\\textwidth}{\\footnotesize \\textit{Note}: Entries are linear regression coefficients with standard errors (clustered on senator) shown in parentheses. The dependent variable is a binary measure of constituent approval. $^*$ indicates $p<0.10$ and $^{**} p<0.05$ (two tailed tests).}",
                                          label="linear_transportation",
                                          digits=3,
                                          digits.extra = 0,
                                          title="The Relationship between Local Visits, Policy Representation, and Approval using Transportation Receipts")

visits_msa_transportation <- stargazer(reg1_msa_transportation, reg3_msa_transportation,reg2_msa_transportation, 
                                       omit=c("copartisan", "electionyear", "seniority", "nokken_poole_dim1", "chair", "power",  "female", "race", "age"),
                                       add.lines=list(c("Senator-MSA Fixed Effects","\\checkmark","\\checkmark","\\checkmark"),
                                                      c("Party-Year Fixed Effects","\\checkmark","\\checkmark","\\checkmark")),
                                       notes.append = FALSE, notes.label = "",
                                       report="vc*s",star.char=c("*","**"),star.cutoffs = c(0.10,0.05),no.space = TRUE,
                                       omit.stat = c("rsq", "ser","f"), font.size = "footnotesize",
                                       dep.var.caption  = "Dependent Variable: Approval (0/1)",
                                       dep.var.labels = "", model.numbers = FALSE,
                                       column.labels=c("Any Visits", "Total Visits","ln(Visits + 1)"), align=TRUE,
                                       covariate.labels=c("Policy Disagreement", "Visits", "Policy Disagreement x Visits"),
                                       notes="\\parbox[t]{.78\\textwidth}{\\footnotesize \\textit{Note}: Entries are linear regression coefficients with standard errors (clustered on senator) shown in parentheses. The dependent variable is a binary measure of constituent approval. $^*$ indicates $p<0.10$ and $^{**} p<0.05$ (two tailed tests).}",
                                       label="linear_transportation",
                                       digits=3,
                                       digits.extra = 0,
                                       title="")
star.panel.out <- star_panel(visits_county_transportation, visits_msa_transportation,panel.label.fontface="bold",
                             panel.names = c("County", "Metropolitan Statistical Area"), same.summary.stats = FALSE)
cat(star.panel.out, sep = '\n', file = "TableE7.tex")

################################################
#Excluding senators who report zero per diems
################################################

data_nozero <- data[data$travmax_msa>0,]
data_nozero <- data_nozero[!is.na(data_nozero$traveled_msa),]

# Visits: County Level
data$visits <- data$traveledonce
reg1_zero <- felm(approval_binary ~ votematchmean2*(visits + copartisan + electionyear + seniority + 
                                                      nokken_poole_dim1 + chair + power +  race + female + age) | member_county + party_year | 0 | icpsr, 
                  data = data[data$travmax>0,], weights=data[data$travmax>0,]$weight_cumulative)

data$visits <- data$log_traveled
reg2_zero <- felm(approval_binary ~ votematchmean2*(visits + copartisan + electionyear + seniority + 
                                                      nokken_poole_dim1 + chair + power +  race + female + age) | member_county + party_year | 0 | icpsr, 
                  data = data[data$travmax>0,], weights=data[data$travmax>0,]$weight_cumulative)

data$visits <- data$traveled
reg3_zero <- felm(approval_binary ~ votematchmean2*(visits + copartisan + electionyear + seniority + 
                                                      nokken_poole_dim1 + chair + power +  race + female + age) | member_county + party_year | 0 | icpsr, 
                  data = data[data$travmax>0,], weights=data[data$travmax>0,]$weight_cumulative)

# Visits: MSA Level
data_nozero$visits <- data_nozero$traveledonce_msa
reg1_msa_zero <- felm(approval_binary ~ votematchmean2*(visits + copartisan + electionyear + seniority + 
                                                          nokken_poole_dim1 + chair + power +  race + female + age) | member_msa + party_year | 0 | icpsr, 
                      data = data_nozero, weights=data_nozero$weight_cumulative)

data_nozero$visits <- data_nozero$log_traveled_msa
reg2_msa_zero <- felm(approval_binary ~ votematchmean2*(visits + copartisan + electionyear + seniority + 
                                                          nokken_poole_dim1 + chair + power +  race + female + age) | member_msa + party_year | 0 | icpsr, 
                      data = data_nozero, weights=data_nozero$weight_cumulative)

data_nozero$visits <- data_nozero$traveled_msa
reg3_msa_zero <- felm(approval_binary ~ votematchmean2*(visits + copartisan + electionyear + seniority + 
                                                          nokken_poole_dim1 + chair + power +  race + female + age) | member_msa + party_year | 0 | icpsr, 
                      data = data_nozero, weights=data_nozero$weight_cumulative)

visits_county_zero <- stargazer(reg1_zero, reg3_zero,reg2_zero, 
                                omit=c("copartisan", "electionyear", "seniority", "nokken_poole_dim1", "chair", "power",  "female", "race", "age"),
                                add.lines=list(c("Senator-County Fixed Effects","\\checkmark","\\checkmark","\\checkmark"),
                                               c("Party-Year Fixed Effects","\\checkmark","\\checkmark","\\checkmark")),
                                notes.append = FALSE, notes.label = "",
                                report="vc*s",star.char=c("*","**"),star.cutoffs = c(0.10,0.05),no.space = TRUE,
                                omit.stat = c("rsq", "ser","f"), font.size = "footnotesize",
                                dep.var.caption  = "Dependent Variable: Approval (0/1)",
                                dep.var.labels = "", model.numbers = FALSE,
                                column.labels=c("Any Visits", "Total Visits","ln(Visits + 1)"), align=TRUE,
                                covariate.labels=c("Policy Disagreement", "Visits", "Policy Disagreement x Visits"),
                                notes="\\parbox[t]{.78\\textwidth}{\\footnotesize \\textit{Note}: Entries are linear regression coefficients with standard errors (clustered on senator) shown in parentheses. The dependent variable is a binary measure of constituent approval. $^*$ indicates $p<0.10$ and $^{**} p<0.05$ (two tailed tests).}",
                                label="linear_zero",
                                digits=3,
                                digits.extra = 0,
                                title="The Relationship between Local Visits, Policy Representation, and Approval Excluding Senators who Report Zero Per Diems")

visits_msa_zero <- stargazer(reg1_msa_zero, reg3_msa_zero,reg2_msa_zero, 
                             omit=c("copartisan", "electionyear", "seniority", "nokken_poole_dim1", "chair", "power",  "female", "race", "age"),
                             add.lines=list(c("Senator-MSA Fixed Effects","\\checkmark","\\checkmark","\\checkmark"),
                                            c("Party-Year Fixed Effects","\\checkmark","\\checkmark","\\checkmark")),
                             notes.append = FALSE, notes.label = "",
                             report="vc*s",star.char=c("*","**"),star.cutoffs = c(0.10,0.05),no.space = TRUE,
                             omit.stat = c("rsq", "ser","f"), font.size = "footnotesize",
                             dep.var.caption  = "Dependent Variable: Approval (0/1)",
                             dep.var.labels = "", model.numbers = FALSE,
                             column.labels=c("Any Visits", "Total Visits","ln(Visits + 1)"), align=TRUE,
                             covariate.labels=c("Policy Disagreement", "Visits", "Policy Disagreement x Visits"),
                             notes="\\parbox[t]{.78\\textwidth}{\\footnotesize \\textit{Note}: Entries are linear regression coefficients with standard errors (clustered on senator) shown in parentheses. The dependent variable is a binary measure of constituent approval. $^*$ indicates $p<0.10$ and $^{**} p<0.05$ (two tailed tests).}",
                             label="linear_zero",
                             digits=3,
                             digits.extra = 0,
                             title="")
star.panel.out <- star_panel(visits_county_zero, visits_msa_zero,panel.label.fontface="bold",
                             panel.names = c("County", "Metropolitan Statistical Area"), same.summary.stats = FALSE)
cat(star.panel.out, sep = '\n', file = "TableE6.tex")

############################
# Media Market Level
############################

data$dist <- data$log_traveled_dma
reg1_dma <- felm(approval_binary ~ votematchmean2*(dist + copartisan + electionyear + seniority + 
                                                     nokken_poole_dim1 + chair + power +  race + female + age) | member_dma + party_year | 0 | icpsr, 
                 data = data, weights=data$weight_cumulative)


data$dist <- data$log_staffed_dma
reg2_dma <- felm(approval_binary ~ votematchmean2*(dist + copartisan + electionyear + seniority + 
                                                     nokken_poole_dim1 + chair + power +  race + female + age) | member_dma + party_year | 0 | icpsr, 
                 data = data, weights=data$weight_cumulative)



data$dist <- data$log_traveled_dma
reg3_dma <- felm(voted_for_inc ~ votematchmean2*(dist + copartisan + nokken_poole_dim1 + chair + power +  race + female + age) | member_dma + party_year | 0 | icpsr, 
                 data = data, weights=data$weight_cumulative)


data$dist <- data$log_staffed_dma
reg4_dma <- felm(voted_for_inc ~ votematchmean2*(dist + copartisan + nokken_poole_dim1 + chair + power +  race + female + age) | member_dma + party_year | 0 | icpsr, 
                 data = data, weights=data$weight_cumulative)


mediamarket <- stargazer(reg1_dma, reg2_dma,reg3_dma,reg4_dma,
                         omit=c("copartisan","electionyear", "seniority", "copartisan", "nokken_poole_dim1", "chair", "power",  "female", "race", "age"),
                         add.lines=list(c("Senator-Media Market Effects","\\checkmark","\\checkmark","\\checkmark","\\checkmark"),
                                        c("Party-Year Fixed Effects","\\checkmark","\\checkmark","\\checkmark","\\checkmark")),
                         notes.append = FALSE, notes.label = "",
                         report="vc*s",star.char=c("*","**"),star.cutoffs = c(0.10,0.05),no.space = TRUE,
                         omit.stat = c("rsq", "ser","f"), font.size = "footnotesize",
                         dep.var.caption  = "",
                         dep.var.labels = c("Approval (0/1)", "Vote for Incumbent (0/1)"), model.numbers = FALSE,
                         multicolumn = TRUE,
                         column.labels=c("ln(Visits + 1)", "ln(Pct. of Staff + 1)", "ln(Visits + 1)", "ln(Pct. of Staff + 1)"), align=TRUE,
                         covariate.labels=c("Policy Disagreement", "Local Activity", "Policy Disagreement x Local Activity"),
                         notes="\\parbox[t]{\\textwidth}{\\footnotesize \\textit{Note}: Entries are linear regression coefficients with standard errors (clustered on senator) shown in parentheses. The dependent variables are binary measures of constituent aproval and vote choice. $^*$ indicates $p<0.10$ and $^{**} p<0.05$ (two tailed tests). Note that this analysis only includes respondents living in counties contained within one media market.}",
                         label="linear_dma",
                         digits=3,
                         digits.extra = 0,
                         title="The Relationship between Local Attentiveness, Policy Representation, and Constituent Evaluations at the Media Market Level")
cat(mediamarket, sep = '\n', file = "TableG1.tex")

